package sea.simulate;

import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import sea.explore.ExploreOutputTypeForm;
import sea.explore.ExploreRangeForm;
import sea.util.PublicParam;
import sea.util.SimHyAHelper;
import sea.util.WinHelper;
import simhya.script.Symbol;


/**
 *
 * This class builds the layout of the main simulate interface
 * 
 * @author  Zhirun Ding
 * 
 * Created on 05/07/2012
 * 
 */

public class SimulateForm extends javax.swing.JDialog {
    
    /** Creates new form SimulateForm */
    public SimulateForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();                    
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        simulationTypeButtonGroup = new javax.swing.ButtonGroup();
        storeDataButtonGroup = new javax.swing.ButtonGroup();
        outputDensityButtonGroup = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        vardataNameText = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        typeLabel = new javax.swing.JLabel();
        ssaRadioButton = new javax.swing.JRadioButton();
        gbRadioButton = new javax.swing.JRadioButton();
        odeRadioButton = new javax.swing.JRadioButton();
        hybridRadioButton = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        initialTimeText = new javax.swing.JTextField();
        finalTimeText = new javax.swing.JTextField();
        burnoutCheckBox = new javax.swing.JCheckBox();
        burnoutText = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        varList = new javax.swing.JList();
        selectAllButton = new javax.swing.JButton();
        deselectButton = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        storeDataLabel = new javax.swing.JLabel();
        allTragectoryRadioButton = new javax.swing.JRadioButton();
        finalStateTimeRadioButton = new javax.swing.JRadioButton();
        outputDensityLabel = new javax.swing.JLabel();
        samplePointsRadioButton = new javax.swing.JRadioButton();
        samplePeriodRadioButton = new javax.swing.JRadioButton();
        samplePointsText = new javax.swing.JTextField();
        samplePeriodText = new javax.swing.JTextField();
        tragectorystatisticsRadioButton = new javax.swing.JRadioButton();
        statestatisticsRadioButton = new javax.swing.JRadioButton();
        backButton = new javax.swing.JButton();
        nextBack = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        modelvarNameText = new javax.swing.JTextField();
        rangeButton = new javax.swing.JButton();
        outputTypeButton = new javax.swing.JButton();
        helpButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sea.SimHyAGui.class).getContext().getResourceMap(SimulateForm.class);
        setTitle(resourceMap.getString("SimulateForm.title")); // NOI18N
        setName("SimulateForm"); // NOI18N
        setResizable(false);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        vardataNameText.setText(resourceMap.getString("vardataNameText.text")); // NOI18N
        vardataNameText.setToolTipText(resourceMap.getString("vardataNameText.toolTipText")); // NOI18N
        vardataNameText.setName("vardataNameText"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel1.setName("jPanel1"); // NOI18N

        typeLabel.setText(resourceMap.getString("typeLabel.text")); // NOI18N
        typeLabel.setName("typeLabel"); // NOI18N

        simulationTypeButtonGroup.add(ssaRadioButton);
        ssaRadioButton.setSelected(true);
        ssaRadioButton.setText(resourceMap.getString("ssaRadioButton.text")); // NOI18N
        ssaRadioButton.setToolTipText(resourceMap.getString("ssaRadioButton.toolTipText")); // NOI18N
        ssaRadioButton.setName("ssaRadioButton"); // NOI18N

        simulationTypeButtonGroup.add(gbRadioButton);
        gbRadioButton.setText(resourceMap.getString("gbRadioButton.text")); // NOI18N
        gbRadioButton.setToolTipText(resourceMap.getString("gbRadioButton.toolTipText")); // NOI18N
        gbRadioButton.setName("gbRadioButton"); // NOI18N

        simulationTypeButtonGroup.add(odeRadioButton);
        odeRadioButton.setText(resourceMap.getString("odeRadioButton.text")); // NOI18N
        odeRadioButton.setToolTipText(resourceMap.getString("odeRadioButton.toolTipText")); // NOI18N
        odeRadioButton.setName("odeRadioButton"); // NOI18N
        odeRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                odeRadioButtonItemStateChanged(evt);
            }
        });

        simulationTypeButtonGroup.add(hybridRadioButton);
        hybridRadioButton.setText(resourceMap.getString("hybridRadioButton.text")); // NOI18N
        hybridRadioButton.setToolTipText(resourceMap.getString("hybridRadioButton.toolTipText")); // NOI18N
        hybridRadioButton.setName("hybridRadioButton"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(ssaRadioButton)
                        .addGap(28, 28, 28)
                        .addComponent(gbRadioButton)
                        .addGap(33, 33, 33)
                        .addComponent(odeRadioButton)
                        .addGap(41, 41, 41)
                        .addComponent(hybridRadioButton))
                    .addComponent(typeLabel))
                .addContainerGap(28, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(typeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ssaRadioButton)
                    .addComponent(gbRadioButton)
                    .addComponent(odeRadioButton)
                    .addComponent(hybridRadioButton))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setForeground(resourceMap.getColor("jLabel4.foreground")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        initialTimeText.setText(resourceMap.getString("initialTimeText.text")); // NOI18N
        initialTimeText.setToolTipText(resourceMap.getString("initialTimeText.toolTipText")); // NOI18N
        initialTimeText.setName("initialTimeText"); // NOI18N

        finalTimeText.setText(resourceMap.getString("finalTimeText.text")); // NOI18N
        finalTimeText.setToolTipText(resourceMap.getString("finalTimeText.toolTipText")); // NOI18N
        finalTimeText.setName("finalTimeText"); // NOI18N

        burnoutCheckBox.setText(resourceMap.getString("burnoutCheckBox.text")); // NOI18N
        burnoutCheckBox.setName("burnoutCheckBox"); // NOI18N
        burnoutCheckBox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                burnoutCheckBoxStateChanged(evt);
            }
        });

        burnoutText.setText(resourceMap.getString("burnoutText.text")); // NOI18N
        burnoutText.setToolTipText(resourceMap.getString("burnoutText.toolTipText")); // NOI18N
        burnoutText.setEnabled(false);
        burnoutText.setName("burnoutText"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        varList.setName("varList"); // NOI18N
        jScrollPane1.setViewportView(varList);

        selectAllButton.setText(resourceMap.getString("selectAllButton.text")); // NOI18N
        selectAllButton.setName("selectAllButton"); // NOI18N
        selectAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectAllButtonActionPerformed(evt);
            }
        });

        deselectButton.setText(resourceMap.getString("deselectButton.text")); // NOI18N
        deselectButton.setName("deselectButton"); // NOI18N
        deselectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deselectButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(deselectButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(selectAllButton))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addComponent(selectAllButton)
                        .addGap(36, 36, 36)
                        .addComponent(deselectButton)))
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.setName("jPanel3"); // NOI18N

        storeDataLabel.setText(resourceMap.getString("storeDataLabel.text")); // NOI18N
        storeDataLabel.setName("storeDataLabel"); // NOI18N

        storeDataButtonGroup.add(allTragectoryRadioButton);
        allTragectoryRadioButton.setSelected(true);
        allTragectoryRadioButton.setText(resourceMap.getString("allTragectoryRadioButton.text")); // NOI18N
        allTragectoryRadioButton.setToolTipText(resourceMap.getString("allTragectoryRadioButton.toolTipText")); // NOI18N
        allTragectoryRadioButton.setName("allTragectoryRadioButton"); // NOI18N
        allTragectoryRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                allTragectoryRadioButtonItemStateChanged(evt);
            }
        });

        storeDataButtonGroup.add(finalStateTimeRadioButton);
        finalStateTimeRadioButton.setToolTipText(resourceMap.getString("finalStateTimeRadioButton.toolTipText")); // NOI18N
        finalStateTimeRadioButton.setLabel(resourceMap.getString("finalStateTimeRadioButton.label")); // NOI18N
        finalStateTimeRadioButton.setName("finalStateTimeRadioButton"); // NOI18N
        finalStateTimeRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                finalStateTimeRadioButtonItemStateChanged(evt);
            }
        });

        outputDensityLabel.setText(resourceMap.getString("outputDensityLabel.text")); // NOI18N
        outputDensityLabel.setName("outputDensityLabel"); // NOI18N

        outputDensityButtonGroup.add(samplePointsRadioButton);
        samplePointsRadioButton.setSelected(true);
        samplePointsRadioButton.setText(resourceMap.getString("samplePointsRadioButton.text")); // NOI18N
        samplePointsRadioButton.setName("samplePointsRadioButton"); // NOI18N
        samplePointsRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                samplePointsRadioButtonItemStateChanged(evt);
            }
        });

        outputDensityButtonGroup.add(samplePeriodRadioButton);
        samplePeriodRadioButton.setText(resourceMap.getString("samplePeriodRadioButton.text")); // NOI18N
        samplePeriodRadioButton.setName("samplePeriodRadioButton"); // NOI18N
        samplePeriodRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                samplePeriodRadioButtonItemStateChanged(evt);
            }
        });

        samplePointsText.setText(resourceMap.getString("samplePointsText.text")); // NOI18N
        samplePointsText.setName("samplePointsText"); // NOI18N

        samplePeriodText.setText(resourceMap.getString("samplePeriodText.text")); // NOI18N
        samplePeriodText.setEnabled(false);
        samplePeriodText.setName("samplePeriodText"); // NOI18N

        storeDataButtonGroup.add(tragectorystatisticsRadioButton);
        tragectorystatisticsRadioButton.setText(resourceMap.getString("tragectorystatisticsRadioButton.text")); // NOI18N
        tragectorystatisticsRadioButton.setName("tragectorystatisticsRadioButton"); // NOI18N
        tragectorystatisticsRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                tragectorystatisticsRadioButtonItemStateChanged(evt);
            }
        });

        storeDataButtonGroup.add(statestatisticsRadioButton);
        statestatisticsRadioButton.setLabel(resourceMap.getString("statestatisticsRadioButton.label")); // NOI18N
        statestatisticsRadioButton.setName("statestatisticsRadioButton"); // NOI18N
        statestatisticsRadioButton.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                statestatisticsRadioButtonItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(statestatisticsRadioButton, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
                        .addGap(36, 36, 36))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(tragectorystatisticsRadioButton, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                        .addGap(18, 18, 18))
                    .addComponent(outputDensityLabel)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(finalStateTimeRadioButton)
                            .addComponent(allTragectoryRadioButton)
                            .addComponent(storeDataLabel)
                            .addComponent(samplePeriodRadioButton)
                            .addComponent(samplePointsRadioButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(samplePeriodText, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)
                            .addComponent(samplePointsText, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(storeDataLabel)
                .addGap(18, 18, 18)
                .addComponent(allTragectoryRadioButton)
                .addGap(16, 16, 16)
                .addComponent(finalStateTimeRadioButton)
                .addGap(18, 18, 18)
                .addComponent(tragectorystatisticsRadioButton)
                .addGap(18, 18, 18)
                .addComponent(statestatisticsRadioButton)
                .addGap(22, 22, 22)
                .addComponent(outputDensityLabel)
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(samplePointsRadioButton)
                    .addComponent(samplePointsText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(samplePeriodRadioButton)
                    .addComponent(samplePeriodText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        backButton.setText(resourceMap.getString("backButton.text")); // NOI18N
        backButton.setName("backButton"); // NOI18N
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });

        nextBack.setText(resourceMap.getString("nextBack.text")); // NOI18N
        nextBack.setName("nextBack"); // NOI18N
        nextBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextBackActionPerformed(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        modelvarNameText.setEditable(false);
        modelvarNameText.setText(resourceMap.getString("modelvarNameText.text")); // NOI18N
        modelvarNameText.setToolTipText(resourceMap.getString("modelvarNameText.toolTipText")); // NOI18N
        modelvarNameText.setEnabled(false);
        modelvarNameText.setName("modelvarNameText"); // NOI18N

        rangeButton.setText(resourceMap.getString("rangeButton.text")); // NOI18N
        rangeButton.setToolTipText(resourceMap.getString("rangeButton.toolTipText")); // NOI18N
        rangeButton.setName("rangeButton"); // NOI18N
        rangeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rangeButtonActionPerformed(evt);
            }
        });

        outputTypeButton.setText(resourceMap.getString("outputTypeButton.text")); // NOI18N
        outputTypeButton.setName("outputTypeButton"); // NOI18N
        outputTypeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                outputTypeButtonActionPerformed(evt);
            }
        });

        helpButton.setText(resourceMap.getString("helpButton.text")); // NOI18N
        helpButton.setName("helpButton"); // NOI18N
        helpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(initialTimeText, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel4))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(burnoutCheckBox)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(burnoutText, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(finalTimeText, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(modelvarNameText))
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addComponent(rangeButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(outputTypeButton))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(backButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(nextBack)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(helpButton))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(vardataNameText, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(vardataNameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(modelvarNameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(outputTypeButton)
                            .addComponent(rangeButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(backButton)
                            .addComponent(nextBack)
                            .addComponent(helpButton)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(initialTimeText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(finalTimeText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(burnoutCheckBox)
                            .addComponent(burnoutText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        isInitData = true;
        this.dispose();
    }//GEN-LAST:event_backButtonActionPerformed

    private void nextBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextBackActionPerformed
        //get simulation type
        if (ssaRadioButton.isSelected()) PublicParam.SimulationType = "SSA";
        if (gbRadioButton.isSelected()) PublicParam.SimulationType = "GB";
        if (odeRadioButton.isSelected()) PublicParam.SimulationType = "ODE";
        if (hybridRadioButton.isSelected()) PublicParam.SimulationType = "HYBRID";
        
        
        PublicParam.PreviousForm = this;
        
        //generate simulate command
        if (!toSimulateCommand()) return;
        
        isInitData = false;
        
        // next form dependency
        if (PublicParam.SimulationType.equals("SSA") || PublicParam.SimulationType.equals("GB")) {
            //SSA,GB
            WinHelper.showDialog(PublicParam.SimulateSGForm, SimulateSGForm.class);
        } else {
            //ODE,HYBRID
            WinHelper.showDialog(PublicParam.SimulateODEForm, SimulateODEForm.class);
        }              
    }//GEN-LAST:event_nextBackActionPerformed

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        if (!isInitData) return;
        
        //set default value
        samplePointsText.setText(String.valueOf(PublicParam.SimHyACommand.getDefaultSamplePoints()));
        
        //init name of simulation
        if (PublicParam.CommandTypeName.equals("explore")) {
            vardataNameText.setText(SimHyAHelper.getNewDataVariableName("EXP", PublicParam.CurrrentModelFileName));
            
            //init the controls of store data 
            allTragectoryRadioButton.setText("trajectory data");
            finalStateTimeRadioButton.setText("final state");
            tragectorystatisticsRadioButton.setText("trajectory statistics");
            statestatisticsRadioButton.setVisible(true);
            //default value
            finalStateTimeRadioButton.setSelected(true);
            
        } else if (PublicParam.CommandTypeName.equals("simulate")){
            vardataNameText.setText(SimHyAHelper.getNewDataVariableName("SIM", PublicParam.CurrrentModelFileName));
            
            //init the controls of store data 
            allTragectoryRadioButton.setText("all trajectory");
            finalStateTimeRadioButton.setText("final state only");
            tragectorystatisticsRadioButton.setText("statistics only");
            //tragectorystatisticsRadioButton.setVisible(false);
            statestatisticsRadioButton.setVisible(false);
            //set default value
            allTragectoryRadioButton.setEnabled(true);
        }
        
        
        //init current model variable
        modelvarNameText.setText(PublicParam.CurrentModelVariableName);
        
        //init model variable of list
        ArrayList<Symbol> listofvars = PublicParam.SimHyACommand.getVariables(PublicParam.CurrentModelVariableName);//.getListOfModelVariables();
        //remove all items in listbox
        varList.removeAll();
        DefaultListModel lm = new DefaultListModel();
        
        //add all mode variable to the listbox
        int[] selectedIndexes = new int[listofvars.size()];
        for (int i = 0; i < listofvars.size(); i++) {
            lm.add(i, listofvars.get(i).name);    
            selectedIndexes[i] = i;
        }
        
        //read all model variable to listbox
        varList.setModel(lm);
        varList.setSelectedIndices(selectedIndexes);
        
        //change title by commandType
        if (PublicParam.CommandTypeName.equals("simulate")) {
            typeLabel.setText("Simulate Type");
            this.setTitle("Simulate");
            rangeButton.setVisible(false);
            outputTypeButton.setVisible(false);
        } else if (PublicParam.CommandTypeName.equals("explore")) {
            typeLabel.setText("Explore Type");
            this.setTitle("Explore");
            rangeButton.setVisible(true);
            outputTypeButton.setVisible(true);
        }
    }//GEN-LAST:event_formComponentShown

    private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllButtonActionPerformed
        int[] selectedIndexes = new int[varList.getModel().getSize()];
        for (int i = 0; i < selectedIndexes.length; i++) {
            selectedIndexes[i] = i;
        }
        //set all items to be selected
        varList.setSelectedIndices(selectedIndexes);
    }//GEN-LAST:event_selectAllButtonActionPerformed

    private void deselectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectButtonActionPerformed
        int[] selectedIndexes = new int[] {-1};
        varList.setSelectedIndices(selectedIndexes);        
    }//GEN-LAST:event_deselectButtonActionPerformed

    private void rangeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rangeButtonActionPerformed
        WinHelper.showDialog(PublicParam.ExploreRangeForm, ExploreRangeForm.class);
    }//GEN-LAST:event_rangeButtonActionPerformed

    void setOutputDensityControlsEnable(boolean isEnabled) {
        outputDensityLabel.setEnabled(isEnabled);
        samplePointsRadioButton.setEnabled(isEnabled);
        samplePointsText.setEnabled(isEnabled && samplePointsRadioButton.isSelected());
        samplePeriodRadioButton.setEnabled(isEnabled);
        samplePeriodText.setEnabled(isEnabled && samplePeriodRadioButton.isSelected());
    }
    
    private void outputTypeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_outputTypeButtonActionPerformed
        WinHelper.showDialog(PublicParam.ExploreOutputTypeForm, ExploreOutputTypeForm.class);
    }//GEN-LAST:event_outputTypeButtonActionPerformed

    private void burnoutCheckBoxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_burnoutCheckBoxStateChanged
        burnoutText.setEnabled(burnoutCheckBox.isSelected());
    }//GEN-LAST:event_burnoutCheckBoxStateChanged

    private void tragectorystatisticsRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_tragectorystatisticsRadioButtonItemStateChanged
        setOutputDensityControlsEnable(tragectorystatisticsRadioButton.isSelected());
    }//GEN-LAST:event_tragectorystatisticsRadioButtonItemStateChanged

    private void statestatisticsRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_statestatisticsRadioButtonItemStateChanged
        setOutputDensityControlsEnable(!statestatisticsRadioButton.isSelected());
    }//GEN-LAST:event_statestatisticsRadioButtonItemStateChanged

    private void finalStateTimeRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_finalStateTimeRadioButtonItemStateChanged
        setOutputDensityControlsEnable(!finalStateTimeRadioButton.isSelected());
    }//GEN-LAST:event_finalStateTimeRadioButtonItemStateChanged

    private void allTragectoryRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_allTragectoryRadioButtonItemStateChanged
        setOutputDensityControlsEnable(allTragectoryRadioButton.isSelected());
    }//GEN-LAST:event_allTragectoryRadioButtonItemStateChanged

    //(If the simulation type is ODE, the options(the Store type) below will be hided
    private void odeRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_odeRadioButtonItemStateChanged
        if (PublicParam.CommandTypeName.equals("simulate")){
            tragectorystatisticsRadioButton.setEnabled(!odeRadioButton.isSelected());
            if (odeRadioButton.isSelected() && tragectorystatisticsRadioButton.isSelected()) {
                allTragectoryRadioButton.setSelected(true);
            }
        } else if (PublicParam.CommandTypeName.equals("explore")){
            //Store Data
            //storeDataLabel.setEnabled(!odeRadioButton.isSelected());
            //allTragectoryRadioButton.setEnabled(!odeRadioButton.isSelected());
            //finalStateTimeRadioButton.setEnabled(!odeRadioButton.isSelected());
            tragectorystatisticsRadioButton.setEnabled(!odeRadioButton.isSelected());
            statestatisticsRadioButton.setEnabled(!odeRadioButton.isSelected());

            //Output Density
            setOutputDensityControlsEnable(!odeRadioButton.isSelected() && !finalStateTimeRadioButton.isSelected());
        }
    }//GEN-LAST:event_odeRadioButtonItemStateChanged

    private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpButtonActionPerformed
       if (PublicParam.CommandTypeName.equals("simulate")){
            WinHelper.showHelp("simulate/simulate");
       } else {
           WinHelper.showHelp("explore/explore");
       }
}//GEN-LAST:event_helpButtonActionPerformed

    private void samplePointsRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_samplePointsRadioButtonItemStateChanged
        samplePointsText.setEnabled(samplePointsRadioButton.isSelected());
        samplePeriodText.setEnabled(!samplePointsRadioButton.isSelected());
    }//GEN-LAST:event_samplePointsRadioButtonItemStateChanged

    private void samplePeriodRadioButtonItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_samplePeriodRadioButtonItemStateChanged
        samplePointsText.setEnabled(!samplePeriodRadioButton.isSelected());
        samplePeriodText.setEnabled(samplePeriodRadioButton.isSelected());
    }//GEN-LAST:event_samplePeriodRadioButtonItemStateChanged
    
    //generate simulate command
    boolean toSimulateCommand() {
        String s = "";
        //data variable
        if (vardataNameText.getText().length() > 0) {
            s += "$" + vardataNameText.getText() + "=";
        }
        //function name
        if (PublicParam.CommandTypeName.equals("explore")) {
            s += "explore($" + modelvarNameText.getText();
        } else if (PublicParam.CommandTypeName.equals("simulate")){
            s += "simulate($" + modelvarNameText.getText();
        }
        //simulate type
        if (ssaRadioButton.isSelected()) {
            //ssa
            s += ",ssa";
        } else if (gbRadioButton.isSelected()) {
            //gb
            s += ",gb";
        } else if (odeRadioButton.isSelected()) {
            //ode
            s += ",ode";
        } else if (hybridRadioButton.isSelected()) {
            //hybrid
            s += ",hybrid";
        }
        
        //Initial Time
        try {
            if (initialTimeText.getText().length() > 0 
                    && Double.valueOf(initialTimeText.getText()) != 0.0) {
                s += ",t0=" + initialTimeText.getText();
            }
        } catch(Exception ex) {            
        }
        
        //Final Time
        try {
            if (finalTimeText.getText().length() > 0 
                    && Double.valueOf(finalTimeText.getText()) != 0.0) {
                s += ",time=" + finalTimeText.getText();
            } else {
                JOptionPane.showMessageDialog(this, "You must input Final Time!");
                finalTimeText.requestFocus();
                return false;
            }
        } catch(Exception ex) {     
                JOptionPane.showMessageDialog(this, "You must input Final Time! \nFinal Time must be float. \nfloat is a floating point number");
                finalTimeText.requestFocus();
                return false;
        }
        
        //Burnout burnout
        try {
            if (burnoutCheckBox.isSelected() && burnoutText.getText().length() > 0 
                    && Double.valueOf(burnoutText.getText()) != 0.0) {
                s += ",burnout=" + burnoutText.getText();
            }
        } catch(Exception ex) {            
        }                
        
        //save
        if (varList.getModel().getSize() == varList.getSelectedValues().length 
                && varList.getModel().getSize() > 0) {
            //select all
            s += ",save=all";
        } else {
            for (int i = 0; i < varList.getSelectedValues().length; i++) {
                if (i == 0) {
                    s += ",save=[";
                } else {
                    s += ",";
                }
                s += varList.getSelectedValues()[i];
            }
            if (varList.getSelectedValues().length > 0) s += "]";
        }
        
        //finalstateonly
        if (PublicParam.CommandTypeName.equals("simulate")) {
            if (finalStateTimeRadioButton.isEnabled() && finalStateTimeRadioButton.isSelected()) {
                s += ",finalstateonly";
            }                
        }
        
        //simulate,Statistics Only
        if (PublicParam.CommandTypeName.equals("simulate")) {
            if (tragectorystatisticsRadioButton.isEnabled() && tragectorystatisticsRadioButton.isSelected()) {
                s += ",store=statonly";
            }                
        }
        
        //store data
        if (PublicParam.CommandTypeName.equals("explore")) {
            //all: all trajectories are saved
            if (allTragectoryRadioButton.isEnabled() && allTragectoryRadioButton.isSelected()) {
                s += ",store=all";
            }
            //trajectory: the statistics for all time points are saved
            if (tragectorystatisticsRadioButton.isEnabled() && tragectorystatisticsRadioButton.isSelected()) {
                s += ",store=trajectory";
            }
            //final: only the final states statistics are saved
            if (finalStateTimeRadioButton.isEnabled() && finalStateTimeRadioButton.isSelected()) {
                s += ",store=final";
            }
            //distribution: the final states of each simulation are saved (default)
            if (statestatisticsRadioButton.isEnabled() && statestatisticsRadioButton.isSelected()) {
                s += ",store=distribution";
            }
        }
        
        //points
        if (samplePointsRadioButton.isEnabled() && samplePointsRadioButton.isSelected() 
                && samplePointsText.getText().length() > 0 && Double.valueOf(samplePointsText.getText()) != 0.0) {
            s += ",points=" + samplePointsText.getText();
        }
        //timestep
        if (samplePeriodRadioButton.isEnabled() && samplePeriodRadioButton.isSelected() 
                && samplePeriodText.getText().length() > 0 && Double.valueOf(samplePeriodText.getText()) != 0.0) {
            s += ",timestep=" + samplePeriodText.getText();
        }        
        
        //range list of explore
        if (PublicParam.CommandTypeName.equals("explore")) {
            //range list can't be empty.
            String rangelist = "";
            if (PublicParam.ExploreRangeForm != null) {
                rangelist = ((ExploreRangeForm)PublicParam.ExploreRangeForm).toExploreRangeExpression();
            }
            if (rangelist.length() == 0) {
                JOptionPane.showMessageDialog(this, "You must input the data of range!Please click the button of 'Range' and input data.");
                return false;
            }
            //append ranglist to s of command
            s += rangelist;
        }
        
        //output type of explore
        if (PublicParam.CommandTypeName.equals("explore") && PublicParam.ExploreOutputTypeForm != null) {
            s += ((ExploreOutputTypeForm)PublicParam.ExploreOutputTypeForm).toExploreOutputTypeExpression();
        }
        
        //set simuldate command to public param
        PublicParam.SimHyACommandExpression = s;
        
        return true;
    }
        
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                SimulateForm dialog = new SimulateForm(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton allTragectoryRadioButton;
    private javax.swing.JButton backButton;
    private javax.swing.JCheckBox burnoutCheckBox;
    private javax.swing.JTextField burnoutText;
    private javax.swing.JButton deselectButton;
    private javax.swing.JRadioButton finalStateTimeRadioButton;
    private javax.swing.JTextField finalTimeText;
    private javax.swing.JRadioButton gbRadioButton;
    private javax.swing.JButton helpButton;
    private javax.swing.JRadioButton hybridRadioButton;
    private javax.swing.JTextField initialTimeText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField modelvarNameText;
    private javax.swing.JButton nextBack;
    private javax.swing.JRadioButton odeRadioButton;
    private javax.swing.ButtonGroup outputDensityButtonGroup;
    private javax.swing.JLabel outputDensityLabel;
    private javax.swing.JButton outputTypeButton;
    private javax.swing.JButton rangeButton;
    private javax.swing.JRadioButton samplePeriodRadioButton;
    private javax.swing.JTextField samplePeriodText;
    private javax.swing.JRadioButton samplePointsRadioButton;
    private javax.swing.JTextField samplePointsText;
    private javax.swing.JButton selectAllButton;
    private javax.swing.ButtonGroup simulationTypeButtonGroup;
    private javax.swing.JRadioButton ssaRadioButton;
    private javax.swing.JRadioButton statestatisticsRadioButton;
    private javax.swing.ButtonGroup storeDataButtonGroup;
    private javax.swing.JLabel storeDataLabel;
    private javax.swing.JRadioButton tragectorystatisticsRadioButton;
    private javax.swing.JLabel typeLabel;
    private javax.swing.JList varList;
    private javax.swing.JTextField vardataNameText;
    // End of variables declaration//GEN-END:variables
    
    boolean isInitData = true;//init listbox before show
}
